<?php
/**
 * Created by PhpStorm.
 * User: WINNERWLY
 * Date: 2018/8/8
 * Time: 9:07
 */

namespace app\index\model;


use think\Model;

class Cooperator extends Model
{
    protected $table = "cooperator";
    protected $insert = ["create_time", "appid", "partner_no"];

    public function scopeIndex($query)
    {
        $query->field("id,name,partner_no,appid,send_count,balance,remark,create_time")->where("is_delete=0");
    }

    public function setCreateTimeAttr()
    {
        return time();
    }

    public function setPartnerNoAttr()
    {
        $res = Model::order("id desc")->page(1, 1)->select();

        $lastId = 100001;
        if ($res && $res[0] && $res[0]["id"]) {
            $lastId = $res[0]["id"] + $lastId;
        }
        return 'MZ' . $lastId;
    }

    public function setAppidAttr()
    {
        return md5(time());
    }
}
